package thread;

public class Demo12 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread=new Thread(()->{
            Thread curTread=Thread.currentThread();
            //currentThread()是Tread的静态方法,通过这个方法就可以获取到调用这个方法线程的实例
            //那个线程调用,就返回的引用就指向哪个线程的实例
            while (!curTread.isInterrupted()){
                System.out.println("hello Tread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    System.out.println("catch捕获了异常");
                    return;
                }
            }
        });
        thread.start();
        Thread.sleep(3000);
        thread.interrupt();
    }
}
